package com.monkeygroup.mygoplus.common.DefinedView;



import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Point;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;

import com.monkeygroup.mygoplus.R;

public class MessageChoosePhotoDialog {
	public interface OnButtonClickListener {
		public void onYesClick(TextView txtMessageText);
		public void onNoClick();
	}

	public static void show(Activity activity, String title, String content,
			final OnButtonClickListener listener,boolean cancel) {
		show(activity, title, content,  "取消","确定", listener,cancel);
	}

	@SuppressLint("NewApi")
	public static void show(Activity activity, String title, String content,String btn1,String btn2,
			final OnButtonClickListener listener,boolean cancel){
		final AlertDialog dialog = new AlertDialog.Builder(activity).setCancelable(cancel).create();// 创建对话框
		dialog.setCanceledOnTouchOutside(cancel);
		dialog.show();

		Window window = dialog.getWindow();// 获取窗口对象
		window.setContentView(R.layout.message_two_view);// 设置内容布局

		TextView txtMessageTitle=(TextView)window.findViewById(R.id.txt_message_title);
		TextView txtMessageText=(TextView)window.findViewById(R.id.txt_message_text);
		TextView txtMessageYes=(TextView)window.findViewById(R.id.txt_message_right);
		TextView txtMessageNo=(TextView)window.findViewById(R.id.txt_message_left);

		
		if(title!=null&&title.length()>0){
			txtMessageTitle.setText(title);
		}
		
		if(content!=null){
			txtMessageText.setText(content);
		}else{
			txtMessageText.setText(R.string.app_name);
		}
		
		
		if(btn1!=null){
			txtMessageNo.setText(btn1);
		}
		
		if(btn2!=null){
			txtMessageYes.setText(btn2);
		}

		WindowManager m = window.getWindowManager();
		Display d = m.getDefaultDisplay();
		WindowManager.LayoutParams p = window.getAttributes();
		Point outSize = new Point();
		d.getSize(outSize);
		// getSize (Point outSize)
		p.width = (int) (outSize.x * 0.8);
		window.setAttributes(p);

		txtMessageYes.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dialog.dismiss();
				if (listener != null) {
					listener.onYesClick(null);
				}
			}
		});
		
		txtMessageNo.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dialog.dismiss();
				if (listener != null) {
					listener.onNoClick();
				}
			}
		});
	}


	@SuppressLint("NewApi")
	public static void showChoose(Activity activity, String title, String content,String btn1,String btn2,
							final OnButtonClickListener listener,boolean cancel){
		final AlertDialog dialog = new AlertDialog.Builder(activity).setCancelable(cancel).create();// 创建对话框
		dialog.setCanceledOnTouchOutside(cancel);
		dialog.show();

		Window window = dialog.getWindow();// 获取窗口对象
		window.setContentView(R.layout.message_notice);// 设置内容布局

		TextView txtMessageTitle=(TextView)window.findViewById(R.id.txt_message_title);
		final EditText txtMessageText=(EditText)window.findViewById(R.id.txt_message_text);
		TextView txtMessageYes=(TextView)window.findViewById(R.id.txt_message_right);
		TextView txtMessageNo=(TextView)window.findViewById(R.id.txt_message_left);

		dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
		dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

		if(title!=null&&title.length()>0){
			txtMessageTitle.setText(title);
		}

		if(content!=null){
			//txtMessageText.setText(content);
		}else{
			//txtMessageText.setText(R.string.app_name);
		}

		if(btn1!=null){
			txtMessageNo.setText(btn1);
		}

		if(btn2!=null){
			txtMessageYes.setText(btn2);
		}

		WindowManager m = window.getWindowManager();
		Display d = m.getDefaultDisplay();
		WindowManager.LayoutParams p = window.getAttributes();
		Point outSize = new Point();
		d.getSize(outSize);
		// getSize (Point outSize)
		p.width = (int) (outSize.x * 0.8);
		window.setAttributes(p);

		txtMessageYes.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dialog.dismiss();
				if (listener != null) {
					listener.onYesClick(txtMessageText);
				}
			}
		});

		txtMessageNo.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				dialog.dismiss();
				if (listener != null) {
					listener.onNoClick();
				}
			}
		});


	}











}
